package top.xiaoqiannb.shapelessdao.client.gui;

import top.xiaoqiannb.shapelessdao.world.inventory.QimenluopanMenu;
import top.xiaoqiannb.shapelessdao.network.QimenluopanButtonMessage;
import top.xiaoqiannb.shapelessdao.ShapelessdaoMod;

import net.minecraft.world.level.Level;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.chat.Component;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.GuiGraphics;

import java.util.HashMap;

import com.mojang.blaze3d.systems.RenderSystem;

public class QimenluopanScreen extends AbstractContainerScreen<QimenluopanMenu> {
	private final static HashMap<String, Object> guistate = QimenluopanMenu.guistate;
	private final Level world;
	private final int x, y, z;
	private final Player entity;
	ImageButton imagebutton_choose01;
	ImageButton imagebutton_choose02;
	ImageButton imagebutton_choose03;
	ImageButton imagebutton_choose04;
	ImageButton imagebutton_choose05;
	ImageButton imagebutton_choose06;
	ImageButton imagebutton_choose07;
	ImageButton imagebutton_choose08;
	ImageButton imagebutton_choose09;

	public QimenluopanScreen(QimenluopanMenu container, Inventory inventory, Component text) {
		super(container, inventory, text);
		this.world = container.world;
		this.x = container.x;
		this.y = container.y;
		this.z = container.z;
		this.entity = container.entity;
		this.imageWidth = 212;
		this.imageHeight = 212;
	}

	@Override
	public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(guiGraphics);
		super.render(guiGraphics, mouseX, mouseY, partialTicks);
		this.renderTooltip(guiGraphics, mouseX, mouseY);
	}

	@Override
	protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int gx, int gy) {
		RenderSystem.setShaderColor(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();

		guiGraphics.blit(new ResourceLocation("shapelessdao:textures/screens/qimenzhonggong.png"), this.leftPos + 72, this.topPos + 72, 0, 0, 68, 68, 68, 68);

		guiGraphics.blit(new ResourceLocation("shapelessdao:textures/screens/qimen.png"), this.leftPos + 0, this.topPos + 0, 0, 0, 212, 212, 212, 212);

		RenderSystem.disableBlend();
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeContainer();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
	}

	@Override
	public void init() {
		super.init();
		imagebutton_choose01 = new ImageButton(this.leftPos + 72, this.topPos + 142, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose01.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(0, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 0, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose01", imagebutton_choose01);
		this.addRenderableWidget(imagebutton_choose01);
		imagebutton_choose02 = new ImageButton(this.leftPos + 142, this.topPos + 2, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose02.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(1, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 1, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose02", imagebutton_choose02);
		this.addRenderableWidget(imagebutton_choose02);
		imagebutton_choose03 = new ImageButton(this.leftPos + 2, this.topPos + 72, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose03.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(2, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 2, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose03", imagebutton_choose03);
		this.addRenderableWidget(imagebutton_choose03);
		imagebutton_choose04 = new ImageButton(this.leftPos + 2, this.topPos + 2, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose04.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(3, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 3, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose04", imagebutton_choose04);
		this.addRenderableWidget(imagebutton_choose04);
		imagebutton_choose05 = new ImageButton(this.leftPos + 72, this.topPos + 72, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose05.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(4, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 4, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose05", imagebutton_choose05);
		this.addRenderableWidget(imagebutton_choose05);
		imagebutton_choose06 = new ImageButton(this.leftPos + 142, this.topPos + 142, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose06.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(5, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 5, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose06", imagebutton_choose06);
		this.addRenderableWidget(imagebutton_choose06);
		imagebutton_choose07 = new ImageButton(this.leftPos + 142, this.topPos + 72, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose07.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(6, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 6, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose07", imagebutton_choose07);
		this.addRenderableWidget(imagebutton_choose07);
		imagebutton_choose08 = new ImageButton(this.leftPos + 2, this.topPos + 142, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose08.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(7, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 7, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose08", imagebutton_choose08);
		this.addRenderableWidget(imagebutton_choose08);
		imagebutton_choose09 = new ImageButton(this.leftPos + 72, this.topPos + 2, 68, 68, 0, 0, 68, new ResourceLocation("shapelessdao:textures/screens/atlas/imagebutton_choose09.png"), 68, 136, e -> {
			if (true) {
				ShapelessdaoMod.PACKET_HANDLER.sendToServer(new QimenluopanButtonMessage(8, x, y, z));
				QimenluopanButtonMessage.handleButtonAction(entity, 8, x, y, z);
			}
		});
		guistate.put("button:imagebutton_choose09", imagebutton_choose09);
		this.addRenderableWidget(imagebutton_choose09);
	}
}
